import { Tsrv } from '@/services';
import Vue from 'vue';

export namespace N_oApprovalProcess {
  export interface oApprovalProcess extends Vue {
    // isMask: boolean;
  }

  export interface I_config {
    liaisonID: string;
    liaisonTitle: string;
    funID: string;
    bpmnID: string;
    // 发起人
    promoter: {
      userID: string;
      userName: string;
    };
    sameData: Array<string>;
    viewedData: Array<string>;
    type: number;
    status: number;
  }

  export interface config {
    modalTitle: string;
    modalSize: [number, number];
    config: I_config;
  }

  export interface I_node {
    rowID: string;
    nodeID: string;
    // 0：审批人、1：条件判断、2：用户组
    type: 0 | 1 | 2;
    order: number;
    content: string;
    // 0；未执行、1；已执行
    confirm: 0 | 1;
    approver: Array<any>;
    data: any;
    time: string;
  }

  export class T_nodeInfo {
    public status: {
      text: string;
      bgColor: string;
    };

    // 开始时间 / 结束时间
    public time: string;

    public type: {
      label: string;
      value: string;
      typeNo: number;
      icon: string;
      extra: string;
    };

    public content: string;

    constructor() {
      this.status = {
        text: '',
        bgColor: '#57a3f3'
      };
      this.time = '';
      this.type = {
        label: '',
        value: '',
        typeNo: -1,
        icon: '',
        extra: ''
      };
      this.content = '';
    }

    public setStatus(status: number) {
      if (status === 0) {
        this.status.text = '未审批';
        this.status.bgColor = '#57a3f3';
      }
      if (status === 1) {
        this.status.text = '审批中';
        this.status.bgColor = 'rgb(75, 255, 45)';
      }
      if (status === 2) {
        this.status.text = '已审批';
        this.status.bgColor = '#eaebef';
      }
      return this;
    }

    public setContent(content: string) {
      this.content = content;
      return this;
    }

    public setTime(time: string) {
      this.time = time;
      return this;
    }

    public setType(tyNo: number, value: string, extra: Array<any>) {
      this.type.typeNo = tyNo;
      if (tyNo === 0) {
        this.type.label = 'approver';
        this.type.value = value;
        this.type.icon = 'wy-account';
      }
      if (tyNo === 1) {
        this.type.label = 'judgment';
        this.type.value = value;
        this.type.icon = 'wy-code-branch';
      }
      if (tyNo === 2) {
        this.type.label = '_sys_user_group';
        this.type.value = value;
        this.type.icon = 'wy-yonghuzu';
        const members = extra.map(el => {
          if (!Tsrv.noValue(el?.userName)) {
            return el.userName;
          }
          return el?.userNO;
        });
        this.type.extra = members.join('，');
      }
    }

    public clearData() {
      this.status = {
        text: '',
        bgColor: '#57a3f3'
      };
      this.time = '';
      this.type = {
        label: '',
        value: '',
        typeNo: -1,
        icon: '',
        extra: ''
      };
      this.content = '';
      return this;
    }
  }

  export interface I_approvalRecord {
    id: string;
    action: {
      label: string;
      value: number;
    };
    operator: {
      label: string;
      value: number;
    };
    content: string;
    time: string;
  }
}
